﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Xml;
using System.Text;

public partial class MessageList : System.Web.UI.Page
{
    protected string tableContent;
    protected void Page_Load(object sender, EventArgs e)
    {
        GetBind();
    }

    protected void GetBind()
    {
        StringBuilder sb = new StringBuilder();

        string filePath = Server.MapPath("xmldata/MessageList.xml");
        DataSet ds = new DataSet();
        ds.ReadXml(filePath);
        if (ds.Tables.Count > 0)
        {
            DataTable dt = ds.Tables[0];
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                sb.Append("<tr>");
                sb.Append("<td width=\"26\"><input type=\"checkbox\" name=\"box\" value='" + dt.Rows[i]["NO"].ToString() + "'onclick=\"checkbox()\"/></td>");
                sb.AppendFormat("<td width=\"20\">" + dt.Rows[i]["NO"].ToString() + "</td>");
                sb.AppendFormat("<td width=\"473\"><a href=\"Message.htm\" target=\"_self\">" + dt.Rows[i]["content"].ToString() + "</a></td>");
                sb.AppendFormat("<td width=\"123\">" + dt.Rows[i]["time"].ToString() + "</td>");
                sb.Append("<td width=\"67\">&nbsp;</td>");
                sb.Append("</tr>");
            }
            tableContent = sb.ToString();
        }
        else
        {
            sb.Append("<tr>");
            sb.Append("<td align=\"center\">暂无消息！</td>");
            sb.Append("</tr>");
            tableContent = sb.ToString();
        }
    }

    protected void btnDelete_Click(object sender, EventArgs e)
    {
        string strT = this.txtId.Text;
        string[] str = strT.Split(',');
        for (int i = 0; i < str.Length - 1; i++)
        {
            XmlDataDocument doc = new XmlDataDocument();
            doc.Load(Server.MapPath("xmldata/MessageList.xml"));
            XmlNode xmlnode = doc.SelectSingleNode("messageList");
            XmlNodeList list = doc.SelectSingleNode("messageList").ChildNodes;
            foreach (XmlNode xn in list)
            {
                XmlElement xe = (XmlElement)xn;
                if (xe.GetAttribute("ID") == str[i])
                {
                    xmlnode.RemoveChild(xe);
                }
            }
            doc.Save(Server.MapPath("xmldata/MessageList.xml"));
        }
        Response.Redirect("MessageList.aspx");
    }
}
